/*
2021-11-21
https://www.acwing.com/problem/content/4081/
*/ 
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;
const int N=1e5+5,mod=1e9+7;
ll f[N];
int T,k;

int main()
{
    cin>>T>>k;
    f[0]=1;
    
    for(int i=1;i<N;i++)
    {
        f[i]=f[i-1];
        if(i>=k) f[i]=(f[i]+f[i-k])%mod;
    }
    for(int i=1;i<N;i++)
        f[i]=(f[i]+f[i-1])%mod;
    
    while(T--)
    {
        int l,r;
        cin>>l>>r;
        cout<<(f[r]-f[l-1]+mod)%mod<<endl;
    }
    
    return 0;
}

